class Admin::BrandsController < AdminController
  def index
    @brands = Brand.all.order("sort ASC").page(params[:page]).per(params[:per])
  end

  def new
    @brand = Brand.new
  end

  def create
    @brand = Brand.new brand_params
    if @brand.save
      redirect_to admin_brands_path, notice: "保存成功！"
    else
      redirect_to admin_brands_path, notice: "保存失败！"
    end
  end

  def edit
    @brand = Brand.find params[:id]
  end

  def update
    @brand = Brand.find params[:id]
    if @brand.update brand_params
      redirect_to admin_brands_path, notice: "更新成功！"
    else
      redirect_to admin_brands_path, notice: "更新失败！"
    end
  end
  
  def destroy
    @brand = Brand.find params[:id]
    if @brand.destroy
      redirect_to admin_brands_path, notice: "删除成功."
    else
      redirect_to admin_brands_path, notice: "删除失败."
    end
  end

  private

  def brand_params
    params.require(:brand).permit(:name, :intro, :published, :avatar, :big_avatar, :sort, :show_index)
  end
end
